# coding: utf-8
# 18-11-15 下午3:35

if __name__ == '__main__':
    import os
    import django
    import sys

    sys.path.append('../../')

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "usercenter.settings")
    django.setup()


from jsonrpcclient.exceptions import ReceivedNon2xxResponseError, ReceivedErrorResponseError  # noqa
import time  # noqa
from rpc_usercenter.rpc_clients.rpc_client import rpc_client  # noqa


def long_time_task():
    t1 = time.time()
    print(int(t1))
    for ii in range(1000):
        try:
            res = rpc_client.rpc_add(1, ii)
            print(res)
        except ReceivedNon2xxResponseError as e:
            print(e, 'ReceivedNon2xxResponseError')
        except ReceivedErrorResponseError as e:
            print(e, 'ReceivedErrorResponseError')
        except Exception as e:
            print(e)
    t2 = time.time()
    print(int((t2 - t1) * 100) / 100.)


if __name__ == '__main__':
    # long_time_task()

    from multiprocessing.pool import Pool
    p = Pool()
    for i in range(4):
        p.apply_async(long_time_task, args=())
    p.close()
    p.join()
